/*
 * $Id: MD5.h,v 1.1 2005-09-08 05:01:36 bacon Exp $
 */

#ifndef _XPP_BAS_MD5_CLASS_
#define _XPP_BAS_MD5_CLASS_

#include <xp/types.h>
#include <xp/macros.h>

/* RFC1321 The MD5 Message-Digest Algorithm */

namespace xpp
{
	namespace bas
	{

		class MD5
		{
		public:
			MD5 ();
		
			void initialize ();
			void update (const void* data, xp_uint32_t len);
			void finalize (xp_byte_t digest[16]);

		protected:
			xp_uint32_t count[2];
			xp_uint32_t state[4];
			xp_byte_t   buffer[64];

			static xp_byte_t padding[64];

			void transform (xp_uint32_t state[4], xp_byte_t block[64]);
			void encode (xp_byte_t* output, xp_uint32_t* input, xp_size_t len);
			void decode (xp_uint32_t* output, xp_byte_t* input, xp_size_t len);
		};

	}
}

#endif
